package com.base.login.controller;

import com.base.common.annotation.Log;
import com.base.common.core.controller.BaseController;
import com.base.common.core.domain.R;
import com.base.common.enums.BusinessType;
import com.base.login.service.ISysLoginService;
import com.base.login.domain.bo.SysLoginBo;
import com.base.login.domain.vo.LoginUserVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 登录认证
 *
 * @author base
 * @date 2023-10-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/auth")
public class SysLoginController extends BaseController {


    @Autowired
    private final ISysLoginService iSysLoginService;

    /**
     * 获取随机数
     * @return
     */
    @GetMapping("/random")
    public R<String> genRandom(){
        return R.ok(iSysLoginService.genRandom());
    }

    /**
     * 单向验证登录
     * @param bo
     * @return
     */
    @Log(title = "用户登录", businessType = BusinessType.LOGIN)
    @PostMapping("/login")
    public R<Boolean> login(@RequestBody SysLoginBo bo){
        return R.ok(iSysLoginService.login(bo));
    }


    /**
     * 查询用户info信息
     * @param bo
     * @return
     */
    @GetMapping("/info")
    public R<LoginUserVo> info(@RequestBody SysLoginBo bo){
        return R.ok(iSysLoginService.info());
    }


    /**
     * 退出登录
     * @return
     */
    @Log(title = "用户退出登录", businessType = BusinessType.LOGOUT)
    @PostMapping("/logout")
    public R<Boolean> logout(){
        return R.ok(iSysLoginService.logout());
    }
}
